var cul = document.querySelector('.ccenter .centerleft ul')
var ceright = document.querySelector('.ccenter .centerleft .ceright')
var celeft = document.querySelector('.ccenter .centerleft .celeft')
var current = 1
var category = ''
requestData()
function requestData() {
sendAjax({
    url:'http://localhost:8888/goods/list',
    data:{
        current,
        category
    },
    success: res => {
        console.log(res);
        var {code, list, total,} = res;
        if(code === 1) {
            // 数据获取成功
            // 渲染
            var str = ''
            list.forEach(v => {
                str += `
                    <li style="float: left">
                        <a href="list.html?id=${v.goods_id}&category=内衣配饰">
                            <img src="${v.img_big_logo}" alt="" width = "200px">
                        </a>
                    </li>
                `
            })
            cul.innerHTML = str
        }
    }
})
}
ceright.onclick = function(){
    next()
}
celeft.onclick = function(){
    prev()
}
function next(total) {
    current++
    if(current > total) {
        current = total
        return
    }
    requestData()
}
function prev() {
    current--
    if(current < 1) {
        current = 1
        return
    }
    requestData()
}

// 获取商品分类 - 发送ajax请求
$.get('http://localhost:8888/goods/category',).then(res => {
    // console.log(res);
    if(res.code === 1){
        $('.auto .list ul li').on('click', 'a', function(){
            // 跳转 - 携带参数（当前点击分类的名称传递到列表页）
            location.href = 'list.html?category='+$(this).text()
        })
       
    }
})